/*
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */


#include "stdinc.h"
#include "ThemeManager.h"
#include "..\client\Util.h"




ThemeManager::~ThemeManager() throw()
{
		SettingsManager::getInstance()->removeListener(this);
		destroyLibrary();
}

void 
ThemeManager::destroyLibrary()
{
	if (m_hResourceInst)
		::FreeLibrary(m_hResourceInst);
	m_hResourceInst = NULL;
}

void ThemeManager::load()
{
	const string strThemaName = SETTING(THEME_MANAGER_THEME_DLL_NAME);
	if ( strThemaName.length() > 0)
	{

		const string strThemePath = Util::getThemesPath() + strThemaName;

		destroyLibrary();

		m_hResourceInst = ::LoadLibraryA( strThemePath.c_str() );

		if (m_hResourceInst != NULL)
			fire(ThemeManagerListener::ResourceChanged(), strThemaName);
	}
}

void	
ThemeManager::initialize()
{
		SettingsManager::getInstance()->addListener(this);
		load();
}
